<?php
class cuencas extends CI_Controller {
	var $titp='Cuencas';
	var $url ='cuencas/';

	function index(){
		redirect($this->url.'filteredgrid');
	}

	function filteredgrid(){
		$this->load->library('rapyd');

		$filter = new datafilter_library();
		$filter->label = 'Cuencas en las cuales la mision del arbol opera en el Estado Merida';
		$sel=array('cuencas.id AS id','cuencas.nombre AS cnombre','zonas.nombre AS znombre','cuencas.caracteristicas AS caracteristicas');
		$filter->db->select($sel);
		$filter->db->from('cuencas');
		$filter->db->join('zonas','cuencas.id_zona=zonas.id');

		//$filter->field('input','cuencas.nombre','Nombre de la cuenca')->attributes(array('style' => 'width:170px'));

                $filter->field('dropdown','id_zona','Nombre de la zona')
			->option('','Seleccionar')
			->options('SELECT id,nombre FROM zonas ORDER BY nombre')
			->attributes(array('style'   => 'width: 200px'))
			->rule('trim|required');


		$filter->buttons('reset','search');
		$filter->build();

		$uri = anchor($this->url.'dataedit/show/<raencode><#id#></raencode>','<#id#>');

		$grid = new datagrid_library();
		$grid->label = 'Lista de las cuencas';
		$grid->per_page = 40;
		$grid->source($filter);

		$grid->column('cnombre','Cuenca',true)->url($this->url.'dataedit/show/{id}');
		$grid->column('znombre','Zona');
		$grid->column('caracteristicas','Características');

		$grid->add_button(array('url'=>$this->url.'dataedit/create'));

		$action = "javascript:window.location.href='".site_url('/')."'";
		$grid->button('btn_reg', 'Regresar', $action, 'TR');
		$grid->build();

		$data['content'] = $filter->output.$grid->output;
		$data['head']    = $this->rapyd->head().script('jquery.js');
		$data['title']   = '';
		$this->load->view('view_ventanas_sola', $data);

	}

	function dataedit(){
		$this->load->library('rapyd');

		$edit = new dataedit_library();
		$edit->label = 'Cuencas';
		$edit->back_url = site_url($this->url.'filteredgrid');

		$edit->source('cuencas');
		$edit->field('input','nombre','Nombre de la cuenca')
			->rule('trim|unique|required');

		$edit->field('dropdown','id_zona','Zona')
			->option('','Seleccionar')
			->options('SELECT id,nombre FROM zonas ORDER BY nombre')
			->attributes(array('style'   => 'width: 200px'))
			->rule('trim|required');

		$edit->field('textarea','caracteristicas','Características de la cuenca')
			->rule('trim');

		$edit->buttons('modify','save','undo','delete','back');

		$edit->build();

		$data['head']    = $this->rapyd->head();
		$data['title']   = '<h1>Caracter&iacute;sticas de la cuenca</h1>';
		$data['content'] = $edit;
		$this->load->view('view_ventanas_sola', $data);
	}

	
}

